﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Model.SystemSetting
{
    [Table("UserInfo")]  //Table属性要添加 System.ComponentModel.DataAnnotations的引用
    public class UserInfo
    {
        [Display(Name="用户编号")]
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]//主键标示
        public int UserId { get; set; }

        [Display(Name = "登录名")]
        [Required(ErrorMessage = "请输入{0}")]
        [StringLength(20, ErrorMessage = "{0}在{2}位到{1}位之间", MinimumLength = 3)]
        public string LoginName { get; set; }  

        [Display(Name = "密码")]
        [Required(ErrorMessage = "请输入{0}")]
        [StringLength(20, ErrorMessage = "{0}在{2}位到{1}位之间", MinimumLength = 6)]
        [DataType(DataType.Password)]
        public string UserPwd { get; set; }

        [Display(Name = "身份证")]
        [Required(ErrorMessage="请输入{0}")]
        [RegularExpression(@"(^\d{18}$)|(^\d{17}(\d|X|x)$)", ErrorMessage = "身份证格式错误！")]
        public string UserIDNo { get; set; }

        [Display(Name = "姓名")]
        [Required(ErrorMessage = "请输入{0}")]
        [StringLength(20, ErrorMessage = "{0}在{2}位到{1}位之间", MinimumLength = 3)]
        public string UserName { get; set; }   

        [Display(Name = "手机")]
        [Required(ErrorMessage = "请输入{0}")]
        [RegularExpression(@"^\d{11}$",ErrorMessage="手机号码必须为11位数字")]
        public string UserMobile { get; set; }

        [Display(Name = "电话")]
        [RegularExpression(@"^\d{7,8}$", ErrorMessage = "电话为7-8位数字")]
        public string UserTel { get; set; }

        [Display(Name = "Email")]
        [Required(ErrorMessage = "请输入{0}")]
        [RegularExpression(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", ErrorMessage = "邮箱格式错误!")]
        public string UserEmail { get; set; }

        [Display(Name = "创建日期")]
        [Required]
        public DateTime CreateTime { get; set; }

        [Display(Name = "用户角色")]
        [Required(ErrorMessage = "请输入{0}")]
        [RegularExpression(@"^\d{1,10}$", ErrorMessage = "请填写数字")]
        public int UserRole { get; set; }

        [Display(Name = "用户部门")]
        [Required(ErrorMessage = "请输入{0}")]
        [RegularExpression(@"^\d{1,10}$", ErrorMessage = "请填写数字")]
        public int UserDept { get; set; }

        [Display(Name = "禁用状态")]  //0可用 1禁用
        [Required(ErrorMessage = "请输入{0}")]
        [Range(0,1,ErrorMessage="请填写数字")]
        public short Forbidden { get; set; }
    }

    public class UserInfoDBContext : DbContext
    {
        public DbSet<UserInfo> UsersDb { get; set; }
    }
}
